layui.define(['table', 'form','my_send'], function(exports){
  var $ = layui.$
  ,table = layui.table
  ,form = layui.form
  , http_proxy = layui.http_proxy;
   //权限管理
   table.render({
    elem: '#LAY-user-manage'
    ,url: http_proxy('/role/getRoleByParams') //模拟接口
    ,parseData:function(res){
      return{
        "code":0
        ,"count":res.total
        ,"data":res.rows
        ,'msg':''
      }
    }
    , cols: [[ //表头
      { type: 'numbers', title: '序号', width: '5%', fixed: 'left', unresize: true }
      , { field: 'urid', hide: true }
      , { field: 'roleName', title: '名称', width: '20%', align: 'center', unresize: true }
      , { field: 'roleCode', title: 'code', width: '20%', align: 'center', unresize: true }
      , { field: 'roleDescribe', title: '描述', width: '45%', align: 'center', unresize: true }
      , { fixed: 'right', title: '操作', width: '10%', align: 'center', toolbar: '#toolbar', unresize: true }
    ]]
  });
  
  //监听工具条
  table.on('tool(LAY-privilege)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.confirm('确定删除此分类？', function(index){
        obj.del();
        layer.close(index);
      });
    } else if(obj.event === 'edit'){
      var tr = $(obj.tr);
      layer.open({
        type: 2
        ,title: '编辑分类'
        ,content: 'privilegeForm.html?upid='+ data.upid
        ,area: ['550px', '300px']
        ,btn: ['确定', '取消']
        ,yes: function(index, layero){
          //获取iframe元素的值
          var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags")
          ,tags = othis.find('input[name="tags"]').val();
          
          if(!tags.replace(/\s/g, '')) return;
          
          obj.update({
            tags: tags
          });
          layer.close(index);
        }
        ,success: function(layero, index){
          //给iframe元素赋值
          var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags").click();
          othis.find('input[name="tags"]').val(data.tags);
        }
      });
    }
  });
  //故障维修记录
  table.render({
    elem: '#LAY-user'
    ,url: http_proxy('/rl/list') //模拟接口
    ,request:{
      pageName:'start'
    }
    ,parseData:function(res){
      debugger
      return{
        "code":0
        ,"count":res.data.count
        ,"data":res.data.list
        ,'msg':''
      }
    }
    ,cols: [[
       {field: 'taskNo', width: 100, title: '任务号'}
      ,{field: 'productCode', title: '设备编号', minWidth: 100}
      ,{field: 'productName', title: '设备名称'}
      ,{field: 'eventtitle', title: '报警标题'}
      ,{field: 'maintenanceFalgName', width: 100, title: '维修方式'}
      ,{field: 'mD', title: '维修日期', minWidth: 100}
      ,{field: 'maintenancePerson', title: '维修人'}
      ,{field: 'maintenanceContent', title: '维修内容'}
      ,{field: 'remark', width: 100, title: '描述'}
      ,{field: 'taskName', title: '工单状态', minWidth: 100}
     
    ]]
    ,page: true
    ,limit: 10
    ,limits: [10, 15, 20, 25, 30]
    ,text: '暂无数据'
  });
  
  //监听工具条
  table.on('tool(LAY-user)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.confirm('确定删除此用户？', function(index){
        obj.del();
        layer.close(index);
      });
    } else if(obj.event === 'edit'){
      layer.open({
        type: 2
        ,title: '编辑'
        ,content: 'userForm.html?uid='+ data.uid
        ,maxmin: true
        ,area: ['550px', '550px']
        ,btn: ['确定', '取消']
        ,yes: function(index, layero){
          var iframeWindow = window['layui-layer-iframe'+ index]
          ,submit = layero.find('iframe').contents().find("#layuiadmin-app-form-edit");

          //监听提交
          iframeWindow.layui.form.on('submit(layuiadmin-app-form-edit)', function(data){
            var field = data.field; //获取提交的字段
            
            //提交 Ajax 成功后，静态更新表格中的数据
            //$.ajax({});              
            obj.update({
              label: field.label
              ,title: field.title
              ,author: field.author
              ,status: field.status
            }); //数据更新
            
            form.render();
            layer.close(index); //关闭弹层
          });  
          
          submit.trigger('click');
        }
      });
    }
  });

  exports('alarmManagement', {})
});